import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class MyImageWidget extends StatelessWidget {
  final String image;
  final double imageWidth;
  final double borderRadius;

  const MyImageWidget({
    super.key,
    required this.image,
    required this.imageWidth,
    this.borderRadius = 8.0, // 默认圆角半径
  });

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(borderRadius),
      child: CachedNetworkImage(
        imageUrl: image,
        placeholder: (context, url) => const Center(
          child: SizedBox(
            width: 20.0,
            height: 20.0,
            child: CircularProgressIndicator(strokeWidth: 2.0),
          ),
        ),
        errorWidget: (context, url, error) => const Icon(Icons.error),
        width: imageWidth,
        height: imageWidth,
        fit: BoxFit.cover,
      ),
    );
  }
}
